/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved. 
 */
package com.icinfo.cloud.provider.punish.service.impl;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.punish.mapper.AppDocumentInfoDetailMapper;
import com.icinfo.cloud.provider.punish.model.AppDocumentInfoDetail;
import com.icinfo.cloud.provider.punish.service.IAppDocumentInfoDetailService;
import com.icinfo.cloud.provider.punish.vo.AssociatedTaskVo;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
 * 描述: app端文书内容宽表 app_document_info_detail 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2022年04月12日
 */
@Service
public class AppDocumentInfoDetailServiceImpl extends MyBatisServiceSupport implements IAppDocumentInfoDetailService {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(AppDocumentInfoDetailServiceImpl.class);

    @Autowired
    private AppDocumentInfoDetailMapper appDocumentInfoDetailMapper;

    @Override
    public AppDocumentInfoDetail selectByPrimaryKey(String id) {
        if (StrUtil.isBlank(id)) {
            throw new BusinessException("id不能为空");
        }
        AppDocumentInfoDetail appDocumentInfoDetail = appDocumentInfoDetailMapper.selectByPrimaryKey(id);
        if (Objects.isNull(appDocumentInfoDetail)) {
            throw new BusinessException("文书信息不存在，请检查");
        }
        return appDocumentInfoDetail;
    }

    @Override
    public int updateAssociatedTaskById(String id, List<AssociatedTaskVo> associatedTaskVoList) {
        AppDocumentInfoDetail appDocumentInfoDetail = new AppDocumentInfoDetail();
        appDocumentInfoDetail.setId(id);
        List<AssociatedTaskVo> associatedInfo = Optional.ofNullable(associatedTaskVoList).orElse(Collections.emptyList());
        appDocumentInfoDetail.setAssociatedInfo(JSON.toJSONString(associatedInfo));
        return appDocumentInfoDetailMapper.updateByPrimaryKeySelective(appDocumentInfoDetail);
    }


}